package com.buddy.qreport.template.config;

import com.buddy.qreport.template.IReportTemplate;

import java.util.*;

/**
 * 模板管理器
 */
public class TemplateManager {

    private volatile static TemplateManager instance;

    private static Object lock = new Object();

    private Map<String, IReportTemplate> templateNameValueMap;

    private Map<String, List<IReportTemplate>> templateTypeValueMap;

    private TemplateManager(){

    }

    public static TemplateManager getInstance() {

        if(instance == null){

            synchronized (lock){

                if(instance == null){

                    instance = new TemplateManager();
                }
            }

        }

        return instance;
    }



    public IReportTemplate getTemplateByName(String name){

        if(templateNameValueMap == null){
            return null;
        }
        return templateNameValueMap.get(name);
    }

    public List<IReportTemplate >getTemplateByType(String type){

        if(templateTypeValueMap == null){
            return null;
        }

        return templateTypeValueMap.get(type);
    }


    public Map<String,List<IReportTemplate>> getTypeValueMap(){

        return this.templateTypeValueMap;
    }

    public List<String> getTypes(){

        if(templateTypeValueMap == null){
            return null;
        }

        return new ArrayList<>(templateTypeValueMap.keySet());
    }

}
